<?php

namespace XYWY\Controller;

/**
 * ProductsController类
 *
 * @since 1.0 <2015-10-21> SoChishun <14507247@qq.com> Added.
 */
class ProductsController extends AppbaseController {

    public function index($id = 22) {
        $data = DXA('POrgDocument/DocumentCategory')->field('title, type_id')->find($id);
        if ($data) {
            if ('1' == $data['type_id']) {
                redirect(U('product_info', 'id=' . $id));
            }
            $this->assign('title', $data['title']);
        }
        $list = DXA('POrgDocument/Document')->get_paging_list(array('category_id' => $id), $show);
        $this->assign('list', $list);
        $this->assign('page', $show);
        $this->display();
    }

    function product_detail($id = 0) {
        $data = $id ? DXA('POrgDocument/Document')->find($id) : array();
        if ($data) {
            $data['content'] = DXA('POrgDocument/DocumentContent')->get_content($id);
        }
        $this->assign('data', $data);
        $title = $data ? DXA('POrgDocument/DocumentCategory')->where(array('id' => $data['category_id']))->getField('title') : '';
        $this->assign('title', $title);
        $this->display();
    }

    function product_info($id = 0) {
        $data = DXA('POrgDocument/DocumentCategoryContent')->find($id);
        $this->assign('data', $data);
        $title = $data ? DXA('POrgDocument/DocumentCategory')->where(array('id' => $id))->getField('title') : '';
        $this->assign('title', $title);
        $this->display();
    }

}
